<?
include_once("../../php/include_all.php");

$act = '';
if (isset($_POST['act']))
    $act = $_POST['act'];
	
if ($act == 'tampil_laporan'){
	$idskpd = $_POST['idskpd'];
	if(is_numeric($idskpd)){
		echo 'ok___';
		view_data ($idskpd);
	}else{
		echo "error";
	}
}else if ($act == 'rincProg'){
	$id = $_POST['id'];
	view_rincian($id);
}else if ($act == 's_rincian'){
	$id = $_POST['id_us'];
	$skpd = $_POST['skpd'];
	$rows = $_POST['rows'];
	for ($i=0; $i<count($rows); $i++){
		exec_query("update mus_usulankecamatan set id_skpd=".$skpd[$i]." where id_usulankec=".$id[$i]);
		echo 'success__';
		//view_data($idskpd);
		logs('Mengubah Usulan Kecamatan','ID usulan '.$id[$i]);
	}
	
}

function view_data($idskpd){
	$tahun = date ('Y');
	$prog = get_datas ("select distinct p.id_program, p.nama_program from mus_program p, mus_kegiatan k, mus_usulankecamatan u, mus_rinc_usulan_kec r where r.id_usulankec=u.id_usulankec and r.status=2 and u.id_kegiatan=k.id_keg and k.id_program=p.id_program and u.id_skpd=$idskpd and u.tahun=$tahun order by p.id_program");
	$no=1;
	$counter = 0;
	?>
    <input type='hidden' name='act' value='s_rincian' />        
    <?php
	if(count($prog) > 0){
		foreach ($prog as $prog){
			?>
            <tr><td><?php echo $no; ?></td><td colspan="6"><?php echo ucfirst($prog['nama_program']); ?></td></tr>
            <?php
			$tampil = get_datas ("select distinct u.id_usulankec, s.id_skpd, s.nama_skpd, k.nama_kegiatan, u.indikator_hasil, u.indikator_program, u.indikator_keluaran, u.target_hasil from mus_usulankecamatan u, mus_rinc_usulan_kec r, mus_kegiatan k, mus_program p, mus_skpd s where s.id_skpd=u.id_skpd and r.id_usulankec=u.id_usulankec and r.status=2 and k.id_keg=u.id_kegiatan and u.id_skpd='$idskpd' and u.tahun='$tahun' and k.id_program=p.id_program and k.id_program = ".$prog['id_program']." order by u.id_usulankec");
			foreach ($tampil as $tampil){
				?>
                             <tr>
                                <td>&nbsp;</td>
                                <input type="hidden" name="id_us[]" value="<?php echo $tampil['id_usulankec'];?>">
                                <input type='hidden' name='rows[]' value='<?php echo $counter++ ; ?>'>
                                <td><a href='#windowRincPro' data-toggle="modal" onclick="showrincian(this)" name="<?php echo $tampil['id_usulankec'];?>"><?php echo $tampil['nama_kegiatan'];?></a></td>
                                <td><?php echo $tampil['indikator_program'];?></td>
                                <td><?php echo $tampil['indikator_keluaran'];?></td>
                                <td><?php echo $tampil['indikator_hasil'];?></td>
                                <td><?php echo $tampil['target_hasil'];?></td>
                                <td>
                                    <select name="skpd[]" id="skpd" class="skpd">
                                        <option id="<?php echo $tampil['id_skpd']?>" value="<?php echo $tampil['id_skpd']?>">-Pilih SKPD-</option>
                                        <?php
                                            $skpd = get_datas('select * from mus_skpd');
                                            foreach($skpd as $skpd){
                                        ?>
                                        <option value="<?php echo $skpd['id_skpd']?>"><?php echo $skpd['nama_skpd']?></option>
                                        <?php
                                        }
                                        ?>
                                    </select>
                                </td>
                            </tr>
                <?php
			}
			$no++;
		}
	}
	$sql = get_datas ("select distinct u.id_usulankec, s.id_skpd, s.nama_skpd, u.indikator_hasil, u.indikator_program, u.indikator_keluaran, u.target_hasil, u.kegiatan from mus_usulankecamatan u, mus_rinc_usulan_kec r, mus_skpd s where s.id_skpd=u.id_skpd and r.id_usulankec=u.id_usulankec and r.status=2 and u.id_skpd='$idskpd' and u.tahun='$tahun' and u.id_kegiatan=0 order by u.id_usulankec");
	foreach($sql as $sql){
		?>
        <tr>
           <td><?php echo $no; ?></td>
           <input type="hidden" name="id_us[]" value="<?php echo $sql['id_usulankec'];?>">
           <input type='hidden' name='rows[]' value='<?php echo $counter++; ?>'>
           <td><a href='#windowRincPro' data-toggle="modal" onclick="showrincian(this)" name="<?php echo $sql['id_usulankec'];?>"><?php echo $sql ['kegiatan']?></a></td>
           <td><?php echo $sql ['indikator_program']?></td>
           <td><?php echo $sql ['indikator_keluaran']?></td>
           <td><?php echo $sql ['indikator_hasil']?></td>
           <td><?php echo $sql ['target_hasil']?></td>
           <td>
						<select name="skpd[]" id="skpd" class="skpd">
                            <option id="<?php echo $sql['id_skpd']?>" value="<?php echo $sql['id_skpd']?>">-Pilih SKPD-</option>
                            <?php
                                $skpd = get_datas('select * from mus_skpd');
                                foreach($skpd as $skpd){
                            ?>
                            <option value="<?php echo $skpd['id_skpd']?>"><?php echo $skpd['nama_skpd']?></option>
                            <?php
                            }
                            ?>
                        </select>           </td>
        </tr>
        <?php
		$no++;
	}
}
function view_rincian($id){
	$t_rincian = get_datas ("select * from mus_rinc_usulan_kec where id_usulankec=$id and status=2 order by prioritas");
	$no=1;
	foreach ($t_rincian as $rin){
		?>
        <tr>
        	<td><?php echo $no;?></td>
        	<td><?php echo $rin['lokasi'];?></td>
        	<td><?php echo $rin['volume'];?></td>
        	<td><?php echo $rin['apbdkab'];?></td>
        	<td><?php echo $rin['apbdprov'];?></td>
        	<td><?php echo $rin['apbn'];?></td>
        	<td><?php echo $rin['prioritas'];?></td>
        </tr>
        <?php
		$no++;
	}
}
?>